<template>
  <div>
    <van-picker
      title="修改性别"
      show-toolbar
      :columns="columns"
      :default-index="localGender"
      @confirm="onCancel"
      @cancel="$emit('close')"
      @change="onChange"
    />
  </div>
</template>

<script>
import { updateUserProfile } from '@/api/user'
export default {
  name: 'UpdateGender',
  props: {
    value: {
      type: Number,
      required: true
    }
  },
  components: {},
  data () {
    return {
      columns: ['男', '女'],
      localGender: this.value
    }
  },
  created () {

  },
  methods: {
    async  onCancel () {
      await updateUserProfile({
        gender: this.localGender
      })
      this.$toast.success('更新成功')
      this.$emit('input', this.localGender)
      this.$emit('close')
    },
    onChange (p, v, i) {
      this.localGender = i
    }
  }
}
</script>

<style lang="less" scoped>
</style>
